//
//  MVCTableViewCell.m
//  Demo_MVC
//
//  Created by 陈冰 on 2020/3/8.
//  Copyright © 2020 ChenBing. All rights reserved.
//

#import "MVVMTableViewCell.h"

@implementation MVVMTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)actionSubBtn:(id)sender {
    [self numSubOrAdd:NO];
}

- (IBAction)actionAddBtn:(id)sender {
    [self numSubOrAdd:YES];
}

- (void)numSubOrAdd:(BOOL)isAdd {
    NSString *numStr = self.numLab.text;
    NSInteger numInt = numStr.integerValue;
    if (isAdd) {
        numInt++;
    } else {
        numInt--;
    }
    self.numLab.text = @(numInt).stringValue;
    // 告诉VC Model 变化
    if (self.delegate && [self.delegate respondsToSelector:@selector(didClickAddBtnWithNum:indexPath:)]) {
        [self.delegate didClickAddBtnWithNum:self.numLab.text indexPath:self.indexPath];
    }
}

@end
